using System;
using System.Collections.Generic;
using CI.Misc;
using NUnit.Framework;
using CI;
using CI.Interfaces;
using CI.Mesopotamia;

namespace Mesopotamia.SystemTests
{
    [TestFixture]
    public class MSRBHostTests
    {
        IScenario _scenario;
        const string SCENARIO_NAME = "SingleOrganism";
        private readonly SimEnv _simEnv = SimEnv.Instance;
        private List<Guid> OrganismsToLoad = new List<Guid>();
        /// <summary>
        /// setup
        /// </summary>
        [SetUp]
        public void Setup()
        {
            // setup a scenario
            _scenario = new ScenarioLocalXML();
            // set the scenario to load
            _scenario.ScenarioName = SCENARIO_NAME;
            // load it
            _scenario.Load();
            // set it to our mocked simulation and fitness checking
            _scenario.SimulationRestrictions = typeof(MockSimulation).ToString();
            _scenario.FitnessFunction = typeof(MockFitnessFunction).ToString();
            _simEnv.ClearBreakFlag();
        }

        /// <summary>
        /// Do a test on a single childOrganism with single physical cell, add and destroy
        /// </summary>
        [Test]
        public void SingleOrganismSinglePhysicalCellShortLifeTrue()
        {
            ScenarioHostBootstrap _bootStrap = new ScenarioHostBootstrap();
            _bootStrap.DAL = new SingleOrganismNoRepoduction();
            Globals.BreakTime = new TimeSpan(0);
            _bootStrap.Start(new MockHostingEnvironmentPhysical(), _scenario, OrganismsToLoad);
        }

        /// <summary>
        /// Do a test on a single childOrganism with single physical cell, add, reproduce and destroy (2mins)
        /// </summary>
        [Test]
        public void SingleOrganismSinglePhysicalCellTimedLifeASexualSingleOffspringTrue()
        {

            ScenarioHostBootstrap _bootStrap = new ScenarioHostBootstrap();
            _bootStrap.DAL = new SingleOrganismASexualRepoduction();
            Globals.BreakTime = new TimeSpan(0, 2, 0);
            _bootStrap.Start(new MockHostingEnvironmentPhysical(), _scenario, OrganismsToLoad);

            _simEnv.TraceLogger.LogDebug(string.Format("Organism Count: {0} Alive {1} Dead {2}", (_bootStrap.HostingEnvironment.Organisms.Alive.Count + _bootStrap.HostingEnvironment.Organisms.Dead.Count), _bootStrap.HostingEnvironment.Organisms.Alive.Count, _bootStrap.HostingEnvironment.Organisms.Dead.Count));

            // check and make sure their are at least 20 alive, most probably 15-21(depends on speed of execution)
            Assert.GreaterOrEqual(_bootStrap.HostingEnvironment.Organisms.Alive.Count, 15, "Alive counts");
        }

        /// <summary>
        /// Do a test on a single childOrganism with single physical cell, add, reproduce and destroy (2mins)
        /// But with multiple children
        /// </summary>
        [Test]
        public void SingleOrganismSinglePhysicalCellTimedLifeASexualMulitpleOffspringTrue()
        {
            //todo : set init ciet for organisms
            ScenarioHostBootstrap _bootStrap = new ScenarioHostBootstrap();
            _bootStrap.DAL = new SingleOrganismASexualRepoductionMultipleChildren();
            Globals.BreakTime = new TimeSpan(0, 2, 0);
            _bootStrap.Start(new MockHostingEnvironmentPhysical(), _scenario, OrganismsToLoad);

            _simEnv.TraceLogger.LogDebug(string.Format("Organism Count: {0} Alive {1} Dead {2}", (_bootStrap.HostingEnvironment.Organisms.Alive.Count + _bootStrap.HostingEnvironment.Organisms.Dead.Count), _bootStrap.HostingEnvironment.Organisms.Alive.Count, _bootStrap.HostingEnvironment.Organisms.Dead.Count));

            // check and make sure their are at least 15 alive, most probably 15-21(depends on speed of execution)
            Assert.GreaterOrEqual(_bootStrap.HostingEnvironment.Organisms.Alive.Count, 15, "Alive counts");
        }
    }
}
